/*!
\copyright  Copyright (c) 2021 - 2022 Qualcomm Technologies International, Ltd.
            All Rights Reserved.
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\version    
\file       bredr_scan_manager_truncated_scan.c
\brief	    Implementation of module managing enabling and disabling truncated page scanning.
*/

#include <message.h>
#include "bredr_scan_manager.h"
#include "bredr_scan_manager_private.h"
#include "bredr_scan_manager_truncated_page_scan.h"

#include "qualcomm_connection_manager.h"

#include "logging.h"

void BredrScanManager_TruncatedPageScanRequest(Task client, bredr_scan_manager_scan_type_t page_type)
{
    DEBUG_LOG("BredrScanManager_TruncatedPageScanRequest page_type:%d lock:%d", page_type, bredrScanManager_GetTaskData()->page_scan.lock);

    if(page_type <= SCAN_MAN_PARAMS_TYPE_MAX)
    {
        MessageSendConditionally(bredrScanManager_GetTask(), BREDR_SCAN_MANAGER_INTERNAL_MESSAGE_TRUNCATED_PAGE_SCAN_REQUEST, NULL, &bredrScanManager_GetTaskData()->page_scan.lock);
        bredrScanManager_InstanceClientAddOrUpdate(bredrScanManager_TruncatedPageScanContext(), client, page_type, FALSE);
    }
}

void BredrScanManager_TruncatedPageScanRelease(Task client)
{
    DEBUG_LOG("BredrScanManager_TruncatedPageScanRelease");

    bredrScanManager_InstanceClientRemove(bredrScanManager_TruncatedPageScanContext(), client);
}

void BredrScanManager_HandleInternalTruncatedPageScanRequest(void)
{
    DEBUG_LOG_VERBOSE("BredrScanManager_HandleInternalTruncatedPageScanRequest");

    bredrScanManager_InstanceRefresh(bredrScanManager_TruncatedPageScanContext());
}
